package com.fsquare.domain.paypal;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.broadleafcommerce.core.order.domain.Order;
import org.broadleafcommerce.core.order.domain.OrderImpl;
import org.broadleafcommerce.profile.core.domain.Customer;
import org.broadleafcommerce.profile.core.domain.CustomerImpl;

@Entity
@Table(name = "PAYPAL_PAYMENT")
@NamedQueries( 
	    {   
	        @NamedQuery(name = "PAYPAL_PAYMENT_BY_CUSTOMER_ID", query = "SELECT pp FROM PayPalPaymentImpl pp WHERE pp.customer.id = :customerId"),
	        @NamedQuery(name = "PAYPAL_PAYMENT_BY_PAYMENT_ID", query = "SELECT pp FROM PayPalPaymentImpl pp WHERE pp.paymentId = :paymentId"),
	        @NamedQuery(name = "PAYPAL_PAYMENT_BY_GUID", query = "SELECT pp FROM PayPalPaymentImpl pp WHERE pp.guid = :guid")
	    }
	 )
public class PayPalPaymentImpl implements PayPalPayment ,Serializable{
	
	private static final long serialVersionUID = 3404849269624184989L;

	@Id
	@GeneratedValue
    private Long id;
	
    @Column(name = "PAYMENT_ID", nullable = false)
    private String paymentId;

    @Column(name = "GUID", nullable=false)
    private String guid;
    
    @ManyToOne (targetEntity = CustomerImpl.class)
    @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID", nullable=false)
    private Customer customer;
    
    @ManyToOne (targetEntity = OrderImpl.class)
    @JoinColumn(name = "ORDER_ID", referencedColumnName = "ORDER_ID", nullable=false)
    private Order order;
    
    @Column(name = "AMOUNT", nullable=false)
    private String amount;
    
    @Column(name = "CURRENCY", nullable=false)
    private String currencyCode;
    
    @Column(name = "REQUEST_DATE", nullable=false)
    private Date requestDate;
    
    @Column(name = "SUCCESS_DATE")
    private Date successDate;

    @Column(name = "PAYMENT_URL")
    private String paymentURL;
    
	@Column(name="PAYMENT_STATE", nullable=false)
	@Enumerated(EnumType.STRING)
	private State state = State.PENDING;
    
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public String getAmount() {
		return amount;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}

	public String getCurrencyCode() {
		return currencyCode;
	}

	public void setCurrencyCode(String currencyCode) {
		this.currencyCode = currencyCode;
	}

	public Date getRequestDate() {
		return requestDate;
	}

	public void setRequestDate(Date requestDate) {
		this.requestDate = requestDate;
	}

	public Date getSuccessDate() {
		return successDate;
	}

	public void setSuccessDate(Date successDate) {
		this.successDate = successDate;
	}

	public String getPaymentId() {
		return paymentId;
	}

	public void setPaymentId(String paymentId) {
		this.paymentId = paymentId;
	}

	public String getPaymentURL() {
		return paymentURL;
	}

	public void setPaymentURL(String paymentURL) {
		this.paymentURL = paymentURL;
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}
}
